#include <stdio.h>
#include<stdlib.h>
#define MAX 100000
void InsertionSort(int A[], int N);
int binarySearch(int A[], int n, int target);
void InsertionSort(int A[], int N) {
	int p, i;
	int Tmp;
	for (p = 0; p < N; p++) {
		Tmp = A[p];
		for (i = p; i > 0 && A[i - 1] > Tmp; i--)
			A[i] = A[i - 1];
		A[i] = Tmp;
	}
}
//二分查找，通过查找确定到场客人是否是单身狗 
int binarySearch(int A[], int n, int target) {
	int left = 0;
	int right = n - 1; // 注意

while (left <= right) { // 注意
	int mid = (right + left) / 2;
	if (A[mid] == target)
		return mid;
	else if (A[mid] < target)
		left = mid + 1; // 注意
	else if (A[mid] > target)
		right = mid - 1; // 注意
}
return -1;

}
int main() {
	int m, A[MAX], d, B[MAX];
	int couple[MAX] = { -1 };//初始定义数组值为-1 
	scanf("%d", &m);//输入夫妻对数 
	for (int i = 0; i < m; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		couple[a] = b;//数组下标和对应的数组元素是一对 
		couple[b] = a;
	}
	int n;
	scanf("%d", &n);//参加客人的数目 
	for (int i = 0; i < n; i++) {
		int t;
		scanf("%d", &t);//输入客人ID 
		A[i] = t;//将客人ID存入数组 
	}
	InsertionSort(A, n);//插入排序，对客人ID进行排序 
	int b, c = 0, h = 0;
	for (int j = 0; j < n; j++) {
		if (couple[A[j]] != -1) {
			b = binarySearch(A, n, couple[A[j]]);
			if (b == -1) {
				c++;
				B[h] = A[j];
				h++;
			}
		}
		else {
			c++;
			B[h] = A[j];
			h++;
		}
	}
	printf("%d\n", c);
	for (int i = 0; i < c; i++) {
		if (i == c - 1)
			printf("%05d", B[i]);
		else
			printf("%05d ", B[i]);
	}
}